package leetcode.problems;

import org.junit.Test;

/**
 * Created by gmwang on 2018/7/23
 * 变小写
 */
public class _0724ToLowerCase {
    /**
     * Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.
     * 实现具有字符串参数str的函数ToLowerCase（），并以小写形式返回相同的字符串。
     * Example 1:
     *
     * Input: "Hello"
     * Output: "hello"
     * Example 2:
     *
     * Input: "here"
     * Output: "here"
     * Example 3:
     *
     * Input: "LOVELY"
     * Output: "lovely"
     */
    public String toLowerCase(String str) {
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<str.length();i++){
            char c = str.charAt(i);
            if(c > 64 && c < 97){
                c = (char)(c + 32);
            }
            sb.append(c);
        }
        return sb.toString();
    }
    @Test
    public void test(){
        String str = "LOVELY";
        String res = toLowerCase(str);
        System.out.println(res);
    }
}
